package com.lwj.project1.RecommendPageFragments;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.lwj.project1.R;
import com.lwj.project1.databaseHelper.ImageUtil;
import com.lwj.project1.databaseHelper.MySqliteOpenHelper;
import com.lwj.project1.myToast.MyToast;

public class ShowGameInfoActivity extends AppCompatActivity {
    private ImageView showGameImg;
    private String img;
    private TextView showGameName;
    private String name;
    private TextView showGameModel;
    private String model;
    private TextView showGameDescription;
    private String description;
    private ImageButton addLike;
    private ImageButton toRent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show_game_info);
        MySqliteOpenHelper mySqliteOpenHelper = new MySqliteOpenHelper(getApplicationContext());
        SharedPreferences sharedPreferences = getSharedPreferences("project_content",MODE_PRIVATE);
        MyToast myToast = new MyToast(getApplicationContext());
        Intent intent = getIntent();
        img = intent.getStringExtra("img");
        name = intent.getStringExtra("name");
        model = intent.getStringExtra("model");
        description = intent.getStringExtra("description");

        showGameImg = findViewById(R.id.show_game_img);
        showGameName = findViewById(R.id.show_game_name_show);
        showGameModel = findViewById(R.id.show_game_model_show);
        showGameDescription = findViewById(R.id.show_game_description_show);
        addLike = findViewById(R.id.addLike);
        toRent = findViewById(R.id.toRent);

        showGameImg.setImageBitmap(ImageUtil.base64ToImage(img));
        showGameName.setText(name);
        showGameModel.setText(model);
        showGameDescription.setText(description);
        addLike.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mySqliteOpenHelper.addLike(sharedPreferences.getString("username",""),mySqliteOpenHelper.findGameCategoryByName(name).getGameCategoryId())){
                    myToast.showToastWithImg("添加成功~",getResources().getDrawable(R.drawable.toast_img));
                }else myToast.showToastWithImg("添加失败~",getResources().getDrawable(R.drawable.toast_img));
            }
        });
    }
}